<?php
namespace App\Admin\Renderable;
use App\Models\WxQuestion;
use App\Wen\Utils\FieldUtils;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class QuestionRender extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new WxQuestion(), function (Grid $grid) {
            global $__MINI_GLOBAL_TENANT_ID__;
            if($__MINI_GLOBAL_TENANT_ID__ > 0){
                $grid->model()->where('tenant_id', '=', $__MINI_GLOBAL_TENANT_ID__);
            }
            $grid->quickSearch(['id', 'title', 'content'])->placeholder('搜索与问题id，标题，内容...')->width(35);
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
//            $grid->column('path', '类目页面路径')->display(function (){
//                return FieldUtils::getQuestionTypes()[$this->type]. '：/pages/common/help?type='. $this->type;
//            });
            $grid->column('title');
//            $grid->column('content');
            $grid->column('type')->using(FieldUtils::getQuestionTypes());
//            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
            $grid->disableActions();
        });
    }
}
